const mysql = require('mysql')
const con = mysql.createConnection({
    host: 'localhost',
    port: '3306',
    user: "root",
    password:'root',
    database: 'shop-12a'
})
con.connect()
function query(sql) {
    return new Promise((resolve,reject) => {
        con.query(sql, (err,data) => {
            if(err){
                reject(err)
            }else{
                resolve(data)
            }
        })
    })
}

// const mock = require('mockjs')
// const {list} = mock.mock({
//     "list|50":[
//         {
//             title: "@ctitle(5,10)",
//             Desct: "@ctitle(10,20)",
//             "price|1-1000": 1,
//             image: "@image(100x100,@color)",
//             "sales|1-10000": 1,
//             "stock|1-10000": 1,
//         }
//     ]
// })
// list.forEach(item => {
//     let sql = `insert into shops (title,Desct,price,image,sales,stock) values("${item.title}","${item.Desct}","${item.price}","${item.image}","${item.sales}","${item.stock}")`
//     console.log(sql)
//     query(sql)
// })

module.exports = query;
